<template>
  <div >
    <div style="text-align:left">
      患者信息：
      <el-tag>姓名:{{patient.real_name}}</el-tag>
      <el-tag>病历号:{{patient.case_number}}</el-tag>
      <el-tag>年龄:{{patient.age}}</el-tag>
      <el-tag>性别:{{patient.gender}}</el-tag>
    </div>
    <el-divider></el-divider>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">检验项目</i>
    </div>
    <el-divider></el-divider>

    <el-table :data="check_patient_table" style="width:80%;margin-top:5px" highlight-current-row @current-change="checkSelectionChange">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="item_code" label="检验编码"></el-table-column>
      <el-table-column prop="item_name" label="检验名称"></el-table-column>
      <el-table-column prop="item_format" label="检验规格"></el-table-column>
      <el-table-column prop="item_price" label="单价"></el-table-column>
      <el-table-column prop="item_type" label="费用分类"></el-table-column>
    </el-table>
    <div align="left">
      <el-tag>已选择的检验项目：{{ checkPatient.item_name }}</el-tag>
    </div>

    <el-descriptions title="确认检验科室和检验医生" :column="2" border style="margin-top:20px;width:50%">
      <el-descriptions-item label="科室选择">
        <el-select v-model="deptment_id" placeholder="选择科室" @change="deptChange">
          <el-option v-for="item in check_dept" :key="item.id" :label="item.dept_name" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="医生选择">
        <el-select v-model="employee_id" placeholder="选择医生">
          <el-option v-for="item in check_employee" :key="item.id" :label="item.realname" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
    </el-descriptions>
    <div style="text-align:left;margin-top:20px">
      <el-button type="primary" @click="addCheckPatient()">开始检验</el-button>
      <el-button type="primary" @click="clearCheckPatient()">重置医生</el-button>
    </div>
  </div>
</template>
<script>
import {isNullMessage} from "../../util/util";
import qs from 'qs';
export default{ 
  methods:{
    //增加患者检验
    addCheckPatient(){
      this.checkPatient["inspection_employee_id"] = this.employee_id;
      if(this.checkPatient["inspection_employee_id"]=="" || this.checkPatient["id"]==""){
        this.$message("请选择医生和检验项目");
      }else{
        this.$http.post("http://localhost:8092/updataInspectionPatient",qs.stringify(this.checkPatient)).then(
        (resp)=>{
          this.$message({
            message: resp.data.msg,
            type: 'success'
          });
          this.getCheckPatientTable();          
        })
      }      
    },
    //清空医生选择
    clearCheckPatient(){
      this.deptment_id = '';
      this.employee_id = '';
    },

    //患者检验项目，选择哪个检验项
    checkSelectionChange(currentRow){
        // console.log(currentRow.id+":"+currentRow.item_name);
        this.checkPatient["id"] = currentRow.id;
        this.checkPatient.item_name = currentRow.item_name;
    },
    //得到患者的检验项目
    getCheckPatientTable(){
      this.$http.get("http://localhost:8092/getInspectionPatient?register_id="+this.patient.id).then(
        (resp)=>{
          this.check_patient_table = resp.data;
        }
      )
    },
    //得到检验科室
    getCheckDept(){
      this.$http.get("http://localhost:8092/getInspectionPatientDept").then(
        (resp)=>{
          this.check_dept = resp.data;
        }
      )
    },
    //科室下拉列表改变
    deptChange(deptVal){
      this.employee_id = "";
      this.getCheckEmployee(deptVal)
    },
    //得到检验医生
    getCheckEmployee(deptment_id){
      this.$http.get("http://localhost:8092/getInspectionPatientEmp?deptment_id="+deptment_id).then(
        (resp)=>{
          this.check_employee = resp.data;
        }
      )
    }
  },
  data(){
    return{
      checkPatient:{
        inspection_employee_id:'',
        id:'',
        item_name:''
      },
      employee_id:'',//选择医生id
      check_employee:[],//检验科室医生列表
      deptment_id:'',//选择科室id
      check_dept:[],//检验科室列表
      check_patient_table:[],//患者的检验项目列表
      patient:{},//患者信息

    }    
  },
  mounted:function() {
    this.patient = JSON.parse(sessionStorage.getItem("inspection_now_patient"));
    if(isNullMessage(this,this.patient,'请先选择患者')){
      this.patient={
        real_name:'',
        case_number:'',
        age:'',
        gender:''
      }
    }else{
      this.getCheckPatientTable();
      this.getCheckDept();
    }
  },
}
</script>
